home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 4
/
Aminet 4 - November 1994.iso
/
aminet
/
util
/
misc
/
gadmget1_5.lha
/
GadMget1.5
/
Source
/
mget_listview2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-01
|
14KB
|
576 lines
#ifndef MGET_LISTVIEW2_C
#define MGET_LISTVIEW2_C
/*
* Source machine generated by GadToolsBox V2.0b
* which is (c) Copyright 1991-1993 Jaba Development
*
* GUI Designed by : Jeremy Friesner
*/
#include <exec/types.h>
#include <exec/libraries.h>
#include <intuition/intuition.h>g
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <clib/wb_protos.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <string.h>
#include "mget_listview2.h"
#include "Gadmget.h"
extern char pnamestring[];
extern struct List *filelist;
extern struct List *getlist;
extern struct Gadget *findgadlist;
extern void *findvi;
extern int appwindow;
extern char *pubscreenname;
extern int screentype;
extern UWORD windowwidth;
extern UWORD windowheight;
extern UWORD windowtop;
extern UWORD windowleft;
extern char windowtitle[];
extern int windowisopen;
extern int screenisopen;
extern char sListFontName[];
extern int nListFontSize;
int screenwidth,screenheight;
extern FILE *fpOut;
extern struct TextFont *listfontdata; /* pointer to font data */
extern struct GfxBase *GraphicsBase; /* needed to determine default system font */
extern BOOL BStartedFromWB;
extern int nTopListTop;
extern int nTopListHeight;
struct Screen *Scr = NULL;
APTR VisualInfo = NULL;
struct Window *mgetWnd = NULL;
struct Window *findwindow = NULL;
struct AppWindow *appwin = NULL;
struct AppMessage *amsg = NULL;
struct MsgPort *awport = NULL;
struct Gadget *mgetGList = NULL;
struct Menu *mgetMenus = NULL;
struct IntuiMessage mgetMsg;
struct Gadget *mgetGadgets[2];
UWORD mgetLeft = 0;
UWORD mgetTop = 12;
UWORD lastcode;
ULONG appwinsig = 0L;
struct TextAttr topaz8 = {
( STRPTR )"topaz.font", 8, 0x00, 0x00 };
struct TextAttr listfont = {
( STRPTR )"topaz.font", 8 , 0x00, 0x00 };
struct NewMenu mgetNewMenu[] = {
/* 0 */ NM_TITLE, (STRPTR)"Project", NULL, 0L, NULL, NULL,
/* 1 */ NM_ITEM, (STRPTR)"Open", (STRPTR)"O", 0, 0L, (APTR)mgetopenfile,
/* 2 */ NM_ITEM, (STRPTR)"Append", (STRPTR)"A", 0, 0L, (APTR) mgetappend,
/* 3 */ NM_ITEM, (STRPTR)"About", NULL, 0, 0L, (APTR)mgetabout,
/* 4 */ NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0L, 0L, NULL,
/* 5 */ NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)mgetquit,
/* 6 */ NM_TITLE, (STRPTR)"Search", NULL, 0L, NULL, NULL,
/* 7 */ NM_ITEM, (STRPTR)"Find", (STRPTR)"F", 0, 0L, (APTR)mgetfind,
/* 8 */ NM_ITEM, (STRPTR)"Find Next", (STRPTR)"N", 0, 0L, (APTR)mgetfindnext,
/* 9 */ NM_ITEM, (STRPTR)"Case Sensitive", (STRPTR)"C", 0|CHECKIT, 0L, (APTR)mgetcase,
/* 10 */ NM_TITLE, (STRPTR)"Output", NULL, 0L, NULL, NULL,
/* 11 */ NM_ITEM, (STRPTR)"Aminet Parse", NULL, 0|CHECKIT, 0L, (APTR)mgetnoparse,
/* 12 */ NM_ITEM, (STRPTR)"Get Files", NULL, 0|CHECKIT, 0L, (APTR)mgetfiles,
/* 13 */ NM_ITEM, (STRPTR)"Get Readmes", NULL, 0|CHECKIT, 0L, (APTR)mgetreadmes,
/* 14 */ NM_ITEM, (STRPTR)"Split Commands", NULL, 0|CHECKIT, 0L, (APTR)mgetsplit,
/* 15 */ NM_ITEM, (STRPTR)"Simple Paths", NULL, 0|CHECKIT, 0L, (APTR)mgetCD,
/* 16 */ NM_ITEM, (STRPTR)"Line Length...", (STRPTR)"L", 0, 0L, (APTR)mgetlinelength,
/* 17 */ NM_END, NULL, NULL, 0, 0L, NULL };
char GadgetTextString0[] = "";
struct NewGadget mgetNGad[] = {
0, 0, 0, 0, (UBYTE *)"Selectable Files", NULL, 0, PLACETEXT_ABOVE, NULL, (APTR)listviewgadgetClicked,
0, 0, 0, 0, (UBYTE *)"Selected Files", NULL, 1, PLACETEXT_BELOW, NULL, (APTR)list2Clicked
};
ULONG mgetGTags[] = {
(GT_Underscore), '_',
(TAG_DONE)
};
UWORD DriPens[] = {
~0 };
int SetupScreen( void )
{
ULONG lflag = 0L;
struct Screen *sTemp = NULL;
struct DrawInfo *screen_drawinfo = NULL;
Scr = NULL;
switch (screentype)
{
case USE_PUBSCREEN:
Scr = LockPubScreen(pubscreenname);
if (Scr == NULL)
{
MakeReq("Couldn't lock public screen!",NULL,"Huh?");
return(1L);
}
screenwidth = Scr->Width;
screenheight = Scr->Height;
break;
case USE_CUSTOMSCREEN:
if ((sTemp = LockPubScreen("Workbench")) != NULL)
{
lflag = GetVPModeID(&(sTemp->ViewPort));
screenwidth = sTemp->Width;
screenheight = sTemp->Height;
}
else
{
screenwidth = 640;
screenheight = 400;
lflag = HIRESLACE_KEY;
}
if (sTemp != NULL) UnlockPubScreen(NULL,sTemp);
if ( ! ( Scr = OpenScreenTags(NULL,
SA_Left, 0,
SA_Top, 0,
SA_Width, screenwidth,
SA_Height, screenheight,
SA_Depth, 2,
SA_Font, &GraphicsBase->DefaultFont,
SA_Type, CUSTOMSCREEN,
SA_DisplayID, lflag,
SA_AutoScroll, TRUE,
SA_Overscan, OSCAN_TEXT,
SA_Pens, &DriPens[0],
SA_Title, pnamestring,
TAG_DONE )))
return( 1L );
break;
case USE_WBSCREEN:
Scr = LockPubScreen("Workbench");
if (Scr == NULL) {MakeReq("Couldn't lock Workbench Screen!",NULL,"Where is it?"); return(1L);}
screenwidth = Scr->Width;
screenheight = Scr->Height;
break;
}
if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
return( 2L );
return( 0L );
}
void CloseDownScreen( void )
{
if ( VisualInfo )
{
FreeVisualInfo( VisualInfo );
VisualInfo = NULL;
}
switch(screentype)
{
case USE_CUSTOMSCREEN:
CloseScreen( Scr );
Scr = NULL;
break;
case USE_PUBSCREEN:
UnlockPubScreen(NULL,Scr);
break;
case USE_WBSCREEN:
UnlockPubScreen(NULL,Scr);
break;
}
screenisopen = 0;
}
int HandlemgetIDCMP( void )
{
struct IntuiMessage *m;
struct MenuItem *n;
int (*func)();
BOOL running = TRUE;
WORD wtop = -1 , wleft = -1, wheight = -1 , wwidth= -1;
struct NewGadget ng;
struct Gadget *g;
while( m = GT_GetIMsg( mgetWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&mgetMsg, (long)sizeof( struct IntuiMessage ));
lastcode = m->Code;
GT_ReplyIMsg( m );
switch ( mgetMsg.Class ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( mgetWnd );
GT_EndRefresh( mgetWnd, TRUE );
break;
case IDCMP_NEWSIZE:
windowtop = mgetWnd->TopEdge;
windowleft = mgetWnd->LeftEdge;
windowheight = mgetWnd->Height;
windowwidth = mgetWnd->Width;
RemoveGList(mgetWnd, mgetGList, -1);
FreeGadgets(mgetGList);
EraseRect(mgetWnd->RPort,mgetWnd->BorderLeft, mgetWnd->BorderTop,
mgetWnd->Width - mgetWnd->BorderRight - 1,
mgetWnd->Height - mgetWnd->BorderBottom - 1);
if (SetupGadgets(g, &ng) == 2L)
{
MakeReq("ListView Gadget Setup Error",NULL,"I wish Jeremy would debug better");
Cleanup();
exit(10);
}
AddGList(mgetWnd, mgetGList, -1, -1, NULL);
RefreshGList(mgetGList, mgetWnd, NULL, -1);
GT_RefreshWindow(mgetWnd, NULL);
RefreshWindowFrame(mgetWnd);
ChangeWindowTitle();
GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[0], mgetWnd, NULL, GTLV_Labels, filelist, TAG_END);
GT_SetGadgetAttrs((struct Gadget *) mgetGadgets[1], mgetWnd, NULL, GTLV_Labels, getlist, TAG_END);
break;
case IDCMP_CLOSEWINDOW:
running = mgetCloseWindow();
break;
case IDCMP_GADGETUP:
case IDCMP_GADGETDOWN:
func = ( void * )(( struct Gadget * )mgetMsg.IAddress )->UserData;
running = func();
break;
case IDCMP_MENUPICK:
while( mgetMsg.Code != MENUNULL ) {
n = ItemAddress( mgetMenus, mgetMsg.Code );
func = (void *)(GTMENUITEM_USERDATA( n ));
running = func();
mgetMsg.Code = n->NextSelect;
}
break;
}
}
return( running );
}
int SetupGadgets(struct Gadget *gadlist, struct NewGadget *ng)
{
UWORD lc, tc;
UWORD offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
UWORD wheight = windowheight - offy;
UWORD wwidth = windowwidth - offx;
UWORD topedge[2], height[2];
BYTE bSizeGadHeight = 8; /* This shouldn't be hardcoded, but how to find out when the window is closed??? */
struct List *thislist = NULL;
topedge[0] = offy;
height[0] = ((int) (.7 * wheight));
topedge[1] = topedge[0] + height[0] + 1;
height[1] = windowheight - topedge[1] - bSizeGadHeight - 2;
nTopListTop = topedge[0];
nTopListHeight = height[0];
/* Put in correct font */
listfont.ta_Name = sListFontName;
if (nListFontSize > 0) listfont.ta_YSize = nListFontSize; else listfont.ta_YSize = 12;
/* a reasonable default, hopefully! */
listfontdata = OpenDiskFont(&listfont);
if (listfontdata == NULL)
{
/* load system default font */
listfontdata = GraphicsBase->DefaultFont;
listfont.ta_YSize = GraphicsBase->DefaultFont->tf_YSize;
if (strlen(sListFontName) > 0)
{
MakeReq("Couldn't find specified font, Sorry!",NULL,"Um, Ok");
strncpy(sListFontName,NUL,1);
}
}
if ( ! ( gadlist = CreateContext( &mgetGList )))
return( 1L );
for( lc = 0, tc = 0; lc < mget_CNT; lc++ )
{
if (lc == 1)
{
thislist = getlist;
}
else
{
thislist = filelist;
}
CopyMem((char * )&mgetNGad[ lc ], (char * )ng, (long)sizeof( struct NewGadget ));
ng->ng_VisualInfo = VisualInfo;
ng->ng_TextAttr = &listfont;
ng->ng_LeftEdge = offx;
ng->ng_TopEdge = topedge[lc];
ng->ng_Width = wwidth - offx;
ng->ng_Height = height[lc];
ng->ng_GadgetText = NULL;
ng->ng_Flags = NULL;
ng->ng_GadgetID = lc + 50;
mgetGadgets[ lc ] = gadlist = CreateGadget(LISTVIEW_KIND, gadlist, ng, GTLV_Top, 0, TAG_END);
while( mgetGTags[ tc ] ) tc += 2;
tc++;
if ( NOT gadlist)
{
return( 2L );
}
}
}
int OpenmgetWindow( void)
{
struct NewGadget ng;
struct Gadget *g;
int titleheight = (Scr->WBorTop + Scr->RastPort.TxHeight + 1);
int nMinHeight;
if (nListFontSize == 0) nListFontSize = GraphicsBase->DefaultFont->tf_YSize; /* get default setting */
nMinHeight = (8 * (nListFontSize + 2));
if (nMinHeight < 90) nMinHeight = 90;
nMinHeight += titleheight;
if ((windowwidth <= 0)||(windowwidth > screenwidth)) windowwidth = screenwidth;
if (windowheight < nMinHeight) windowheight = nMinHeight;
if ((windowheight <= 0)||(windowheight > screenheight)) windowheight = screenheight - titleheight;
if ((windowleft <= 0)||(windowleft > screenwidth)) windowleft = 0;
if ((windowleft+windowwidth) > screenwidth) windowwidth -= windowleft;
if ((windowtop <= 0)||(windowtop > screenheight)) windowtop = titleheight;
if ((windowtop+windowheight) > screenheight) windowheight -= windowtop;
if ((windowwidth <= 0)||(windowwidth > screenwidth))
{
windowwidth = screenwidth;
windowleft = 0;
}
if ((windowheight <= 0)||(windowheight > screenheight))
{
windowheight = screenheight - titleheight;
windowtop = titleheight;
}
if (SetupGadgets(g, &ng) == 2L) return(2L);
if ( ! ( mgetMenus = CreateMenus( mgetNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
return( 3L );
LayoutMenus( mgetMenus, VisualInfo, TAG_DONE );
switch (screentype)
{
case USE_PUBSCREEN:
if ( ! ( mgetWnd = OpenWindowTags( NULL,
WA_Left, windowleft,
WA_Top, windowtop,
WA_Width, windowwidth,
WA_Height, windowheight,
WA_PubScreen, Scr,
WA_PubScreenFallBack, TRUE,
WA_IDCMP, LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE,
WA_Flags, WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, mgetGList,
WA_Title, windowtitle,
WA_ScreenTitle,pnamestring,
WA_MinWidth, 155,
WA_MinHeight, nMinHeight,
WA_MaxWidth, -1,
WA_MaxHeight, -1,
TAG_DONE )))
return( 4L );
break;
case USE_CUSTOMSCREEN:
if ( ! ( mgetWnd = OpenWindowTags( NULL,
WA_Left, windowleft,
WA_Top, windowtop,
WA_Width, windowwidth,
WA_Height, windowheight,
WA_CustomScreen, Scr,
WA_IDCMP, LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE,
WA_Flags, WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, mgetGList,
WA_Title, windowtitle,
WA_ScreenTitle,pnamestring,
WA_MinWidth, 155,
WA_MinHeight, nMinHeight,
WA_MaxWidth, -1,
WA_MaxHeight, -1,
TAG_DONE )))
return( 4L );
break;
case USE_WBSCREEN:
if ( ! ( mgetWnd = OpenWindowTags( NULL,
WA_Left, windowleft,
WA_Top, windowtop,
WA_Width, windowwidth,
WA_Height, windowheight,
WA_IDCMP, LISTVIEWIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_NEWSIZE,
WA_Flags, WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, mgetGList,
WA_Title, windowtitle,
WA_ScreenTitle,pnamestring,
WA_MinWidth, 155,
WA_MinHeight, nMinHeight,
WA_MaxWidth, -1,
WA_MaxHeight, -1,
TAG_DONE )))
return( 4L );
if (appwindow == 1)
{
awport = CreateMsgPort();
if (awport == NULL)
{
appwindow = 0;
return(4L);
}
appwin = AddAppWindow(1, 0, mgetWnd, awport, NULL);
if (appwin == NULL)
{appwindow = 0;}
else
appwinsig = 1L << awport->mp_SigBit;
}
break;
}
TurnOnAllMenuItems(mgetMenus);
SetMenuStrip( mgetWnd, mgetMenus );
GT_RefreshWindow( mgetWnd, NULL );
return( 0L );
}
void ClosemgetWindow( void )
{
if ( mgetMenus ) {
ClearMenuStrip( mgetWnd );
FreeMenus( mgetMenus );
mgetMenus = NULL; }
if ( findwindow ) {
CloseWindow( findwindow );
FreeGadgets(findgadlist);
FreeVisualInfo(findvi);
findwindow = NULL;
}
if (appwin) {
RemoveAppWindow(appwin);
/* throw out any leftover messages */
while(amsg = (struct AppMessage *) GetMsg(awport))
ReplyMsg((struct Message *) amsg);
DeleteMsgPort(awport);
}
if ( mgetWnd ) {
CloseWindow( mgetWnd );
windowisopen = 0;
mgetWnd = NULL;
}
if ( mgetGList ) {
FreeGadgets( mgetGList );
mgetGList = NULL;
}
}
#endif